<include file="public@header" />
</head>
<body>
<div class="wrap">
	<ul class="nav nav-tabs">
		<li><a href="{:url('/user/admin_index/index')}">所有用户</a></li>
		<li class="active"><a >用户详细信息</a></li>
	</ul>
	<form method="post" class="form-horizontal margin-top-20 js-ajax-form" action="{:url('/company/admin_user/editMorePost')}">

		<div class="form-group">
			<label for="name" class="col-sm-2 control-label"><span class="form-required">*</span>姓名</label>
			<div class="col-md-2 col-sm-10">
				<input type="text" class="form-control" id="name" name="post[name]" value="{$post.name}">
			</div>


			<label for="id_card" class="col-sm-2 control-label"><span class="form-required">*</span>身份证号</label>
			<div class="col-md-2 col-sm-10">
				<input type="text" class="form-control" id="id_card" name="post[id_card]"  value="{$post['id_card']}">
			</div>
		</div>

		<div class="form-group">
			<label for="category_id" class="col-sm-2 control-label"><span class="form-required">*</span>用户类型</label>
			<div class="col-md-2">
				<select class="form-control" id="category_id" name="post[category_id]" >
					<option value="">请选择分类</option>
					<volist name="member_category" id="vo">
						<php>
							$selected="";
							if($vo->id==$post['category_id']){
							$selected="selected";
							}
						</php>

						<option value="{$vo.id}" {$selected}>{$vo.name}</option>
					</volist>
				</select>

				<input type="hidden" id="category_name" name="post[category_name]" value="{$post['category_name']}">
			</div>


			<label for="group_id" class="col-sm-2 control-label"><span class="form-required">*</span>所在群</label>
			<div class="col-md-2 col-sm-10">

				<select class="form-control" id="group_id" name="post[group_id]" >


					<volist name="member_group" id="vo">
						<php>
							$selected="";
							if($vo->id==$post['group_id']){
							$selected="selected";
							}
						</php>
						<option value="{$vo.id}"  data-text="{$vo.name}" {$selected}>{$vo.name}</option>
					</volist>

				</select>

				<input type="hidden" id="group_name" name="post[group_name]" value="{$post['group_name']}">
			</div>

		</div>

		<div class="form-group">
			<label for="breed_status_id" class="col-sm-2 control-label"><span class="form-required">*</span>孕育状态</label>
			<div class="col-md-2 col-sm-10">
				<select class="form-control" id="breed_status_id" name="post[breed_status_id]" >
					<volist name="breed_status" id="vo">

						<php>
							$selected="";
							if($vo->id==$post['breed_status_id']){
							$selected="selected";
							}
						</php>
						<option value="{$vo.id}" {$selected}>{$vo.name}</option>
					</volist>
				</select>

				<input type="hidden" id="breed_status_name" name="post[breed_status_name]" value="{$post['breed_status_name']}">
			</div>

			<label for="relation_category_id" class="col-sm-2 control-label"><span class="form-required">*</span>关系</label>
			<div class="col-md-2 col-sm-10">
				<select class="form-control" id="relation_category_id" name="post[relation_category_id]" >
					<volist name="relation_category" id="vo">
						<php>
							$selected="";
							if($vo->id==$post['relation_category_id']){
							$selected="selected";
							}
						</php>
						<option value="{$vo.id}" {$selected}>{$vo.name}</option>
					</volist>
				</select>

				<input type="hidden" id="relation_category_name" name="post[relation_category_name]" value="{$post['relation_category_name']}">
			</div>
		</div>

		<div class="form-group">
			<label for="description" class="col-sm-2 control-label">个人简介</label>
			<div class="col-md-6 col-sm-10">
					<textarea class="form-control" name="post[description]" id="description" style="height: 50px;"
							  placeholder="请填写简介">{$post['description']}</textarea>
			</div>
		</div>


		<div class="form-group">
			<label for="province" class="col-sm-2 control-label">所在地区</label>
			<div class="col-md-2 col-sm-10">


				<select class="form-control" id="province" name="post[province_id]" >
					<php>$select = $districts['options'][0]['id'] == 0 ? "selected" : "";</php>
					<option value="" {$select} data-text="">请选择</option>
					<foreach name="districts['options'][0]['options']" item="vo">
						<php>$select = $districts['options'][0]['id'] == $vo['id'] ? "selected" : "";</php>
						<option value="{$vo.id}" {$select} data-text="{$vo.name}">{$vo.name}</option>
					</foreach>
				</select>
			</div>

			<div class="col-md-2 col-sm-10">

				<select class="form-control" id="city" name="post[city_id]" >
					<php>$select = $districts['options'][1]['id'] == 0 ? "selected" : "";</php>
					<option value="" {$select} data-text="">请选择</option>
					<foreach name="districts['options'][1]['options']" item="vo">
						<php>$select = $districts['options'][1]['id'] == $vo['id'] ? "selected" : "";</php>
						<option value="{$vo.id}" {$select} data-text="{$vo.name}">{$vo.name}</option>
					</foreach>
				</select>
			</div>

			<div class="col-md-2 col-sm-10">
				<select class="form-control" id="country" name="post[country_id]" >
					<php>$select = $districts['options'][2]['id'] == 0 ? "selected" : "";</php>
					<option value="" {$select} data-text="">请选择</option>
					<foreach name="districts['options'][2]['options']" item="vo">
						<php>$select = $districts['options'][2]['id'] == $vo['id'] ? "selected" : "";</php>
						<option value="{$vo.id}" {$select} data-text="{$vo.name}">{$vo.name}</option>
					</foreach>
				</select>
			</div>



			<div class="col-md-2 col-sm-10">
				<select class="form-control" id="area" >
					<php>$select = $districts['options'][3]['id'] == 0 ? "selected" : "";</php>
					<option value="" {$select} data-text="">请选择</option>
					<foreach name="districts['options'][3]['options']" item="vo">
						<php>$select = $districts['options'][3]['id'] == $vo['id'] ? "selected" : "";</php>
						<option value="{$vo.id}" {$select} data-text="{$vo.name}">{$vo.name}</option>
					</foreach>
				</select>
			</div>

			<input type="hidden" id="province_name" name="post[province_name]" value="{$post['province_name']}">

			<input type="hidden" id="city_name" name="post[city_name]" value="{$post['city_name']}">

			<input type="hidden" id="country_name" name="post[country_name]" value="{$post['country_name']}">

			<input type="hidden" id="district_id" name="post[district_id]" value="{$default_district}">
			<input type="hidden" id="district_name" name="post[district_name]" value="{$districts['name']}">


		</div>

		<div class="form-group">
			<label for="input-address" class="col-sm-2 control-label">详细地址</label>
			<div class="col-md-6 col-sm-10">
				<input type="text" class="form-control" id="input-address" name="post[address]" value="{$post['address']}">
			</div>
		</div>

		<div class="form-group">
			<label for="postcode" class="col-sm-2 control-label">邮政编码</label>
			<div class="col-md-2 col-sm-10">
				<input type="text" class="form-control" id="postcode" name="post[postcode]" value="{$post['postcode']}">
			</div>
		</div>


		<div class="form-group">
			<label for="company_id" class="col-sm-2 control-label"><span class="form-required">*</span>所属企业</label>
			<div class="col-md-4 col-sm-10">
				<select class="form-control" id="company_id" name="post[company_id]" >
					<option value=""  data-text="">请选择</option>
					<volist name="company_list" id="vo">
						<php>
							$selected="";
							if($vo->id==$post['company_id']){
							$selected="selected";
							}
						</php>
						<option value="{$vo.id}" {$selected}>{$vo.name}</option>
					</volist>
				</select>

				<input type="hidden" id="company_name" name="post[company_name]" value="{$post['company_name']}">
			</div>


		</div>




		<div class="form-group">
			<label   class="col-sm-2 control-label">资质</label>

			<div class="col-md-6 col-sm-10">
				<ul id="files" class="pic-list list-unstyled form-inline">
					<notempty name="post.more.files">
						<foreach name="post.more.files" item="vo">
							<php>$file_url=cmf_get_file_download_url($vo['url']);</php>
							<li id="saved-file{$key}">
								<input id="file-{$key}" type="hidden" name="file_urls[]"
									   value="{$vo.url}">
								<input class="form-control" id="file-{$key}-name" type="text"
									   name="file_names[]"
									   value="{$vo.name}" style="width: 200px;" title="图片名称">
								<a id="file-{$key}-preview" href="{$file_url}" target="_blank">下载</a>
								<a href="javascript:uploadOne('文件上传','#file-{$key}','file');">替换</a>
								<a href="javascript:(function(){$('#saved-file{$key}').remove();})();">移除</a>
							</li>
						</foreach>
					</notempty>
				</ul>
				<a href="javascript:uploadMultiImage('附件上传','#files','files-item-tpl');"
				   class="btn btn-sm btn-default">选择文件</a>
			</div>
		</div>





		<div class="form-group">
			<div class="col-sm-offset-2 col-sm-10">

				<input type="hidden" name="post[id]" value="{$id}" />
				<button type="submit" class="btn btn-primary js-ajax-submit">保存</button>
			</div>
		</div>
	</form>
</div>

<script type="text/html" id="files-item-tpl">
	<li id="saved-file{id}">
		<input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
		<input class="form-control" id="file-{id}-name" type="text" name="file_names[]" value="{name}"
			   style="width: 200px;" title="文件名称">
		<a id="file-{id}-preview" href="{preview_url}" target="_blank">下载</a>
		<a href="javascript:uploadOne('文件上传','#file-{id}','file');">替换</a>
		<a href="javascript:(function(){$('#saved-file{id}').remove();})();">移除</a>
	</li>
</script>



<link rel="stylesheet" href="__STATIC__/js/select2/css/select2.min.css">

<script src="__STATIC__/js/select2/js/select2pinyin.js?v=201802271547"></script>

<script>

    $(function () {
        var $province = $("#province");
        var $city = $("#city");
        var $country = $("#country");
        var $area = $("#area");
        var $district_id = $("#district_id");
        var $district_name = $("#district_name");

        var $company_id = $("#company_id");
        var $group_id = $("#group_id");

        var empty = "<option value='' data-text=''>请选择</option>";




        $group_id.select2();
        $company_id.select2();

        $province.select2();
        $city.select2();
        $country.select2();
        $area.select2();

        $province.on('change', function () {
            var province = $province.find("option:selected");
            if (province.val().length == 0) {
                $city.html(empty);
                $country.html(empty);
                $area.html(empty);
                $district_id.val(0);
            } else {
                $.post("{:url('/company/admin_index/district')}", {parentid: province.val(), type: "json"}, function (data) {
                    var options = empty;
                    for (var i = 0; i < data.data.length; i++) {
                        options += "<option value='" + data.data[i].id + "' data-text='" + data.data[i].name + "'>" + data.data[i].name + "</option>"
                    }
                    $city.html(options);
                    $country.html(empty);
                    $area.html(empty);
                });
                $district_id.val(province.val());
            }
            $district_name.val(province.data("text"));
        });
        $city.on('change', function () {
            var province = $province.find("option:selected");
            var city = $city.find("option:selected");
            if (city.val().length == 0) {
                $country.html(empty);
                $area.html(empty);
                $district_id.val(province.val());
            } else {
                $.post("{:url('/company/admin_index/district')}", {parentid: city.val(), type: "json"}, function (data) {
                    var options = empty;
                    for (var i = 0; i < data.data.length; i++) {
                        options += "<option value='" + data.data[i].id + "' data-text='" + data.data[i].name + "'>" + data.data[i].name + "</option>"
                    }
                    $country.html(options);
                    $area.html(empty);
                });
                $district_id.val($city.val());
            }
            $district_name.val(province.data("text") + city.data("text"));
        });
        $country.on('change', function () {
            var province = $province.find("option:selected");
            var city = $city.find("option:selected");
            var country = $country.find("option:selected");
            if (country.val().length == 0) {
                $area.html(empty);
                $district_id.val(city.val());
            } else {
                $.post("{:url('/company/admin_index/district')}", {parentid: country.val(), type: "json"}, function (data) {
                    var options = empty;
                    for (var i = 0; i < data.data.length; i++) {
                        options += "<option value='" + data.data[i].id + "' data-text='" + data.data[i].name + "'>" + data.data[i].name + "</option>"
                    }
                    $area.html(options);
                });
                $district_id.val(country.val());
            }
            $district_name.val(province.data("text") + city.data("text") + country.data("text"));
        });
        $area.on('change', function () {
            var province = $province.find("option:selected");
            var city = $city.find("option:selected");
            var country = $country.find("option:selected");
            var area = $area.find("option:selected");
            $district_name.val(province.data("text") + city.data("text") + country.data("text") + area.data("text"));
            if (area.val().length == 0) {
                $district_id.val(country.val());
            } else {
                $district_id.val(area.val());
            }
        });

    })

    $("form").submit(function(e){

        $("#province_name").val($("#province").find("option:selected").data("text"));
        $("#city_name").val($("#city").find("option:selected").data("text"));
        $("#country_name").val($("#country").find("option:selected").data("text"));

        $("#category_name").val($("#category_id").find("option:selected").text());


        $("#company_name").val($("#company_id").find("option:selected").text());
        $("#relation_category_name").val($("#relation_category_id").find("option:selected").text());
        $("#breed_status_name").val($("#breed_status_id").find("option:selected").text());
        $("#group_name").val($("#group_id").find("option:selected").text());

        //return false;
    });

</script>
<script src="__STATIC__/js/admin.js"></script>
</body>
</html>